package view.views.dialogContentViews;

import java.awt.FlowLayout;

import javax.swing.BoxLayout;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import model.Constants;
import view.components.IPTextArea;
import view.listeners.AddSubnetFocusListener;

public class SubnetBoxPanel extends JPanel {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private final IPTextArea ipText;
	private final JTextField nameText;
	private final JTextField sizeField;
	private final JTextField suffixField;

	public SubnetBoxPanel() {
		this.setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
		this.addMouseListener(new SubnetBoxPanelMouseAdapter(this));

		JPanel leftContent = new JPanel();
		leftContent.setLayout(new BoxLayout(leftContent, BoxLayout.Y_AXIS));
		JPanel labelPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
		JLabel label = new JLabel(Constants.ADDNETADDRESS);
		labelPanel.add(label);
		leftContent.add(labelPanel);
		JPanel textPanel = new JPanel(labelPanel.getLayout());
		ipText = new IPTextArea();
		textPanel.add(ipText);
		leftContent.add(textPanel);
		JPanel textLabelPanel = new JPanel(labelPanel.getLayout());
		JLabel textLabel = new JLabel(Constants.SUBNETNAME);
		textLabelPanel.add(textLabel);
		leftContent.add(textLabelPanel);
		JPanel textFieldPanel = new JPanel(labelPanel.getLayout());
		nameText = new JTextField(10);
		nameText.setBorder(null);
		textFieldPanel.add(nameText);
		leftContent.add(textFieldPanel);

		JPanel rightContent = new JPanel();
		rightContent.setLayout(new BoxLayout(rightContent, BoxLayout.Y_AXIS));
		JPanel sizeLabelPanel = new JPanel(labelPanel.getLayout());
		JLabel sizeLabel = new JLabel(Constants.SUBNETSIZE);
		sizeLabelPanel.add(sizeLabel);
		rightContent.add(sizeLabelPanel);
		JPanel sizeFieldPanel = new JPanel(labelPanel.getLayout());
		sizeField = new JTextField(5);
		sizeField.setBorder(null);
		sizeField.addFocusListener(new AddSubnetFocusListener(ipText, this));
		sizeFieldPanel.add(sizeField);
		rightContent.add(sizeFieldPanel);
		JPanel suffixLabelPanel = new JPanel(labelPanel.getLayout());
		JLabel suffixLabel = new JLabel(Constants.SUBNETSUFFIX);
		suffixLabelPanel.add(suffixLabel);
		rightContent.add(suffixLabelPanel);
		JPanel suffixFieldPanel = new JPanel(labelPanel.getLayout());
		suffixField = new JTextField(5);
		suffixField.setBorder(null);
		suffixField.addFocusListener(new AddSubnetFocusListener(ipText, this));
		suffixFieldPanel.add(suffixField);
		rightContent.add(suffixFieldPanel);

		this.add(leftContent);
		this.add(rightContent);
	}

	public IPTextArea getIpText() {
		return ipText;
	}

	public JTextField getNameText() {
		return nameText;
	}

	public JTextField getSizeField() {
		return sizeField;
	}

	public JTextField getSuffixField() {
		return suffixField;
	}

}
